package com.mallify.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mallify.common.model.system.SystemMenu;
import com.mallify.service.mapper.SystemMenuMapper;
import com.mallify.service.service.SystemMenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * SystemMenuServiceImpl 接口实现
 * +----------------------------------------------------------------------
 * | HANSON [ HANSON赋能开发者，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Licensed HANSON并不是自由软件，未经许可不能去掉HANSON相关版权
 * +----------------------------------------------------------------------
 * | Author: HANSON Team <hanson0622@126.com>
 * +----------------------------------------------------------------------
 */
@Service
public class SystemMenuServiceImpl extends ServiceImpl<SystemMenuMapper, SystemMenu> implements SystemMenuService {

    @Resource
    private SystemMenuMapper systemMenuMapper;

    /**
     * 获取所有菜单
     *
     * @return List<SystemMenu>
     */
    @Override
    public List<SystemMenu> findAllCatalogue() {
        LambdaQueryWrapper<SystemMenu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SystemMenu::getIsDelete, false);
        queryWrapper.eq(SystemMenu::getIsShow, true);
        queryWrapper.ne(SystemMenu::getMenuType, "A");
        return systemMenuMapper.selectList(queryWrapper);
    }

    @Override
    public List<SystemMenu> getAllPermissions() {
        LambdaQueryWrapper<SystemMenu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SystemMenu::getIsDelete, false);
        queryWrapper.ne(SystemMenu::getMenuType, "M");
        return systemMenuMapper.selectList(queryWrapper);
    }

    @Override
    public List<SystemMenu> findPermissionByUserId(Integer userId) {
        return systemMenuMapper.findPermissionByUserId(userId);
    }

    /**
     * 获取用户路由
     * @param userId 用户id
     * @return List
     */
    @Override
    public List<SystemMenu> getMenusByUserId(Integer userId) {
        return systemMenuMapper.getMenusByUserId(userId);
    }
}